﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace IceDog.Lib.IceDogMath
{
    class DMath
    {
        /// <summary>
        /// 获取数组最大值
        /// </summary>
        /// <param name="array">数组</param>
        /// <returns>最大值</returns>
        public static int GetMaxValue(int[] array)
        {
            int maxVal = array[0];
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] > maxVal)
                {
                    maxVal = array[i];
                }
            }
            return maxVal;
        }
        /// <summary>
        /// 获取数组最小值
        /// </summary>
        /// <param name="array">数组</param>
        /// <returns>最小值</returns>
        public static int GetMinValue(int[] array)
        {
            int minVal = array[0];
            for (var i = 0; i < array.Length; i++)
            {
                if (array[i] < minVal)
                {
                    minVal = array[i];
                }
            }
            return minVal;
        }
        /// <summary>
        /// 获取一定数量的斐波那契数
        /// </summary>
        /// <param name="num">要获取的数量，最大为100</param>
        /// <returns></returns>
        public static string GetFibonaci(int num)
        {
            if (num > 100)
            {
                return "error";
            }
            string str = string.Empty;
            /*
             * 实现思路：
             * 0 1 1 2 3 5 8
             * 除了前两位可以看出输出的值为前两位之和
             */
            BigInteger a = 0, b = 1;
            for (int i = 0; i < num; i++)
            {
                if (i == num - 1)
                {
                    str += a;
                }
                else
                {
                    str += a + " , ";
                }
                var temp = a + b;
                a = b;
                b = temp;
            }
            return str;
        }
    }
}
